<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script type="importmap">
    {
        "imports": {
            "three": "./build/three.module.js",
            "three/addons/": "./examples/jsm/"
        }
    }
</script>
<script type="module">
    import * as THREE from 'three';
    import { Orbitrols } from 'three/addons/controls/OrbitControls.js';
    import Stats from 'three/addons/libs/stats.module.js';
    import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
    import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

    const width = window.innerWidth;
    const height = window.innerHeight;

    // 创建三维场景
    const scene = new THREE.Scene()
    // 添加辅助坐标轴
    const axesHelper = new THREE.AxesHelper(150);
    scene.add(axesHelper)

    // 模型
    const geometry = new THREE.BoxGeometry(100, 100, 100);
    const material = new THREE.MeshLambertMaterial({ // 材质
        color: 0x00ffff, //设置材质颜色
        transparent: true,//开启透明
        opacity: 0.5,//设置透明度
    })
    const mesh = new THREE.Mesh(geometry, material)
    mesh.position.set(50, 50, 50)
    scene.add(mesh);


    //向量Vector3对象表示方向
    const axis = new THREE.Vector3(50, 50, 50);
    axis.normalize(); //向量归一化
    // 沿着axis轴表示方向平移100
    mesh.translateOnAxis(axis, 50);


    // 创建相机 拍摄物体
    const camera = new THREE.PerspectiveCamera(30, width / height, 1, 3000)
    camera.position.set(500, 500, 500)
    camera.lookAt(0, 0, 0)


    // 平行光
    const directionalLight = new THREE.AmbientLight(0xffffff, 1);
    directionalLight.position.set(50, 50, 70);
    scene.add(directionalLight);
    const dirLightHelper = new THREE.PointLightHelper(directionalLight, 10);
    scene.add(dirLightHelper);

    // 创建渲染器 呈现相机拍摄的场景
    const renderer = new THREE.WebGLRenderer()
    renderer.setSize(width, height);

    //设置背景颜色
    renderer.setClearColor(0x444444, 1); //设置背景颜色

    // 设置场景像素比
    renderer.setPixelRatio(window.devicePixelRatio);

    const angle = THREE.MathUtils.degToRad(30);
    console.log('Math.PI', angle);

    renderer.render(scene, camera);


    document.body.appendChild(renderer.domElement);

    const controls = new OrbitControls(camera, renderer.domElement);
    // 如果OrbitControls改变了相机参数，重新调用渲染器渲染三维场景
    controls.addEventListener('change', function () {
        renderer.render(scene, camera); //执行渲染操作
    });//监听鼠标、键盘事件


</script>

</html>